{extend name="layout/base"}

{block name="content"}

<table id="demo" lay-filter="test"></table>
<script type="text/html" id="headerBal">
    <a lay-event="add" class="layui-btn layui-btn-primary">添加</a>
</script>
<script type="text/html" id="type" >
{{# if(d.bill_type == -1){ }}
    <div>按金额</div>
{{# }else{ }}
    <div>按比例</div>
{{# }}}
</script>
<script type="text/html" id="status" >
    {{# if(d.status == 2){ }}
    <span class="layui-badge layui-bg-blue">已添加</span>
    {{# }else{ }}
    <span class="layui-badge">未添加</span>
    {{# }}}
</script>
<script type="text/html" id="done" >
    <a class="layui-btn layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
layui.use(['jquery', 'table','form','laydate'], function () {
    var $ = layui.jquery,
        table = layui.table;
    
    var accountlist = table.render({
        elem: '#demo',
        url: 'listsSharingReceiver',
        toolbar: '#headerBal',
        page: true, 
        cols: [[ 
        {field: 'merid', title: '商家ID'},
        {field: 'amount', title: '分账金额(元)',templet:function(d){
            return d.amount/100
        }},
        {field: 'ratio', title: '分账比例'},
        {field: 'bill_type', title: '分账类型',templet:'#type'},
        {field: 'type', title: '接收方类型'},
        {field: 'name', title: '姓名|商家全称'},
        {field: 'account', title: '接收方帐号'},    
        {field: 'status', title: '状态',templet:'#status'},
        {field: 'done', title: '操作',templet:'#done'}
        ]]
    });
    //监听头部工具栏
    table.on('toolbar(test)', function(obj){
        var checkStatus = table.checkStatus(obj.config.id);
        switch(obj.event){
            case 'add':
            var index = layer.open({
                type: 2,
                title: '添加分账商户',
                skin: 'layui-layer-rim',
                area: ['100%','100%'], 
                content: '/manager/Sharing/add',                
            });
            break;
        };
    });
    //监听工具条 
    table.on('tool(test)', function(obj){
        var data = obj.data; 
        var layEvent = obj.event;
        if(layEvent == 'del'){
            layer.confirm('确定要删除？', function(index){            
                $.ajax({
                    type:'post',
                    url:'removeReceiver',
                    data:{
                        reid:data.reid
                    },
                    success:function(res){
                        if(res.code == 0){
                            layer.msg(res.msg)
                            accountlist.reload()
                        }else{
                            layer.msg(res.msg)
                        }
                    }
                })
                layer.close(index);
            }); 
        } 
    });    
}) 
</script>
{/block}